//
//  BaseTabBarViewController.m
//  老司机发车了
//
//  Created by 斌 on 16/8/5.
//  Copyright © 2016年 斌. All rights reserved.
//

#import "BaseTabBarViewController.h"
#import "FriendViewController.h"
#import "MusicViewController.h"
#import "NewsViewController.h"
#import "SideBarBaseViewController.h"

@interface BaseTabBarViewController ()

@end

@implementation BaseTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBar.barTintColor = [UIColor whiteColor];
    self.tabBar.tintColor = [UIColor blueColor];
    self.tabBar.translucent = NO;
    
    [self createControllers];
    
    // 添加观察者
    [self.tabBarController addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
    
    if (self.view.frame.origin.x > 0) {
        NSLog(@"1");
    }
    
}

// 当被观察者的属性的值发生改变之后 系统会自动在观察者的类中自动调用这个方法
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context{
    
    BaseTabBarViewController *vc = object;
    NSLog(@"%f",vc.view.frame.origin.x);
    NSLog(@"%@",change);
}



- (void)createControllers {
    
    // 资讯
    NewsViewController *newsVC = [[NewsViewController alloc] init];
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:newsVC];
    newsVC.tabBarItem.title = @"资讯";
    newsVC.navigationItem.title = @"资讯";
    newsVC.tabBarItem.image = [UIImage imageNamed:@"资讯"];
    [self addChildViewController:nav1];
    
    // 音乐
    MusicViewController *musicVC = [[MusicViewController alloc] init];
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:musicVC];
    musicVC.tabBarItem.title = @"音乐";
    musicVC.navigationItem.title = @"音乐";
    musicVC.tabBarItem.image = [UIImage imageNamed:@"音乐"];
    [self addChildViewController:nav2];
    
    
    // 好友
    FriendViewController *friendVC = [[FriendViewController alloc] init];
    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:friendVC];
    friendVC.tabBarItem.title = @"好友";
    friendVC.navigationItem.title = @"好友";
    friendVC.tabBarItem.image = [UIImage imageNamed:@"好友"];
    [self addChildViewController:nav3];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
